package edu.gdit.health.dao;

import edu.gdit.health.model.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;
//@Mapper注解标记这个接口作为一个映射接口
@Mapper
public interface SysUserDao {
    @Select("select * from sys_user t")
    List<SysUser>getAll();

    @Select("select ** from sys_user t where t.id=#{id}")
    SysUser getById(Integer id);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into sys_user(user_id, username, password, nickname, headImgUrl, phone,telephone,email,birthday,sex,status, createTime,updateTime) \" + " +
            "\"values(#{userId}, #{username}, #{password}, #{nickname}, #{headImageUrl}, #{phone},#{telephone},\" +\n" +
            "\"#{email},#{birthday},#{sex},#{status}, now(),now())")
    int save(SysUser user);

    @Update("UPDATE'sys_user'SET"+
        "'user_id'=#{userId},'createTime'=#{createTime},"+
        "`nickname`=#{nickname}, `phone`=#{phone}, `telephone`=#{telephone}, " +
        "`email`=#{email}, `birthday`=#{birthday} "+
        "WHERE (`id`=#{id}) LIMIT 1 ")
    int update(SysUser user);
    @Delete("delete from sys_user where id = #{id}")
    int delete(Integer id);
}
